/**
 * @author Daivd chow
 *
 * 上午10:06:49
 */
package com.cbts.util;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 用于读取applicationContext中的bean
 */
public class SpringApplicationContext implements ApplicationContextAware {

	private static ApplicationContext context; 
	/* 
	 * @see org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
	 */
	public void setApplicationContext(ApplicationContext context)
			throws BeansException {
		// zqd 上午10:06:49
		this.context=context;
	}
	
	public static Object getSpringBean(String beanName){
		if(beanName!=null){
			return context==null?null:context.getBean(beanName);
		}else
			return null;
	}
	
	public static String[] getBeanDefinitionNames(){
		return context.getBeanDefinitionNames();
	}

}
